<?php
/**
 * Created by PhpStorm.
 * User: Asnyc
 * Date: 2017/12/18
 * Time: 14:48
 * class: 商家
 */

namespace app\api\model;


use think\Request;

class Store extends BaseModel
{
    protected $table = 'storeinfo';
    // protected $hidden = []; 设置需要隐藏的字段

    /**
     * @return \think\model\relation\HasMany
     * 商家菜单关联模型
     */
    public function getStoreMenu(){
        return $this->hasMany('Storemenu','storeid');
    }

    /**
     * @return false|static[]
     * 查询所有商家信息
     */
    public static function  getallstore(){
        $allstore = Store::all();
        return $allstore;
    }

    /**
     * @param $id
     * @return null|static
     * 根据商家id查询商家信息
     */
    public static function getstorebyid($id){
        $store = Store::get($id);
        return $store;
    }

    /**
     * @param $id
     * @return mixed
     * 根据商家id查询该商家菜单
     */
    public static function getmenubyid($id){
        $menu = StoreModel::with('getStoreMenu')->find($id);
        return $menu;
    }

    /**
     * @return $this
     * 根据关键字模糊搜索商家
     */
    public static function search(){
        $value = Request::instance()->param('storeName');
        $res = self::where('storeName','like',"%$value%")->find();
        return $res;
    }
}